<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 定义函数
        // 完美数
        var foo = function fun(a) {
            var sum = 0;
            for(i = 1 ; i < a ; i++) {
                if (a % i === 0) {
                    sum += i;   
                }      
            }  
            if (sum === a) {
                console.log(a + "是完美数");
            } else {
                console.log(a + "不是完美数");
            }
        };
        // 调用函数
        foo(6);
        foo(9);
        foo(28);
        foo(30);
    </script>
</head>
<body>
    
</body>
</html>